﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.AutoCAD.Interop;
namespace Congducsan
{
    class ClsSanTn
    {
        public AcadApplication mvarobjApp;
        public long Soroda;
        public object ArrDimTdT;
        public object ArrDimTdD;
        public object ArrDimTcT;
        public object ArrDimTcD;
        public String TlCd;
        private Double mvarSauckH1;
        private Double mvarSaubeH2;
        private Double mvarSaubeH3;
        private Double mvarSauckH4;
        private Double mvarDaytuong;
        private Double mvarCaotuongH;
        private Double mvarDaysanh1;
        private Double mvarDaybeh2;
        private Double mvarDaysanH3;
        private Double mvarDayckb;
        private Double mvarDayckb1;
        private Double mvarDaythanhbeb2;
        private Double mvarVatthanha;
        private Double mvarDaisanL;
        private Double mvarDaibeL1;
        private Double mvarDaisanL2;
        private Double mvarRonggod;
        private Double mvarCkgod1;
        private Double mvarMoCk;
        private long mvarSophandoan;
        private object mvarDocPd;
        private int mvarTl;
        private int mvarTlT;
        private Double mvarHsKc;
        private Double mvarTraiphai;
        private Boolean mvarKtVuongGoc;
        private Double mvarTlB;
        private Double mvarRongT;
        private Double mvarRongD;
        private String mvarVlTn;
        private Double mvarLopdem;
        private Double mvarCaoH2;
        private Double mvarSauCk;
        private Double mvarGocxien;
        private Boolean mvarRoda;
        private Double mvarRongRoda;
        private Double mvarCaoRoda;
        private Double mvarDaiRoda;
        private long mvarHangRoda;
        private ClsCommon Com;
        private Double mvarCaochuG;
        private Double mvarCaochuT;
        private Double ArrDao;
        public object Tdden;
        const double Pi = 3.14159265358979;

        private void Class_Terminate()
        {
            Com = null;
        }
        private void Class_Initialize()
        {
            Com =new ClsCommon();
        }
        public Double CaochuG
        {
            set { mvarCaochuG = value; }
            get { return mvarCaochuG * TlDim; }
        }
        public Double CaochuT
        {
            set { mvarCaochuT = value; }
            get { return mvarCaochuT * TlDim; }
        }
        //'******************** THUOC TINH - PROPERTIES ******************
        //'Thuoc tinh kich thuoc
        public Double HsKc
        {
            set { mvarHsKc = value; }
            get { return mvarHsKc; }
        }
        public Double RongRoda
        {
            set { mvarRongRoda = value; }
            get { return mvarRongRoda; }
        }
        public Double CaoRoda
        {
            set { mvarCaoRoda = value; }
            get { return mvarCaoRoda; }
        }
        public Double DaiRoda
        {
            set { mvarDaiRoda = value; }
            get { return mvarDaiRoda; }
        }
        public long HangRoda
        {
            set { mvarHangRoda = value; }
            get { return mvarHangRoda; }
        }
        public Boolean Roda
        {
            set { mvarRoda = value; }
            get { return mvarRoda; }
        }
        public Double GocXien
        {
            set { mvarGocxien = value; }
            get { return mvarGocxien * Pi / 180; }
        }
        public Double Gocdoi()
        {
            return 0.5 * Pi - GocXien;
        }
        public Double CaoH2
        {
            set { mvarCaoH2 = value; }
            get { return mvarCaoH2; }
        }
        public Double SauCk
        {
            set { mvarSauCk = value; }
            get { return mvarSauCk; }
        }
        public Double Lopdem
        {
            set { mvarLopdem = value; }
            get { return mvarLopdem; }
        }
        public String VlTn
        {
            set { mvarVlTn = value; }
            get { return mvarVlTn; }
        }
        public Double MoCk
        {
            set { mvarMoCk = value; }
            get { return mvarMoCk; }
        }
        public Double Ckgod1
        {
            set { mvarCkgod1 = value; }
            get { return mvarCkgod1; }
        }
        public Double Ronggod
        {
            set { mvarRonggod = value; }
            get { return mvarRonggod; }
        }
        public Double DaisanL2
        {
            set { mvarDaisanL2 = value; }
            get { return mvarDaisanL2; }
        }
        public Double DaibeL1
        {
            set { mvarDaibeL1 = value; }
            get { return mvarDaibeL1; }
        }
        public Double DaisanL
        {
            set { mvarDaisanL = value; }
            get { return mvarDaisanL; }
        }
        public Double Vatthanha
        {
            set { mvarVatthanha = value; }
            get { return mvarVatthanha; }
        }
        public Double Daythanhbeb2
        {
            set { mvarDaythanhbeb2 = value; }
            get
            {
                if (KTVuongGoc)
                {
                    return mvarDaythanhbeb2 / Math.Sin(GocXien);
                }
                else
                {
                    return mvarDaythanhbeb2;
                }
            }
        }
        public Double Dayckb1
        {
            set { mvarDayckb1 = value; }
            get
            {
                if (KTVuongGoc)
                {
                    return mvarDayckb1 / Math.Sin(GocXien);
                }
                else
                {
                    return mvarDayckb1;
                }
            }
        }
        public Double Dayckb
        {
            set { mvarDayckb = value; }
            get
            {
                if (KTVuongGoc)
                {
                    return mvarDayckb / Math.Sin(GocXien);
                }
                else
                {
                    return mvarDayckb;
                }
            }
        }
        public Double DaysanH3
        {
            set { mvarDaysanH3 = value; }
            get { return mvarDaysanH3; }
        }
        public Double Daybeh2
        {
            set { mvarDaybeh2 = value; }
            get { return mvarDaybeh2; }
        }
        public Double Daysanh1
        {
            set { mvarDaysanh1 = value; }
            get { return mvarDaysanh1; }
        }
        public Double Daytuong
        {
            set { mvarDaytuong = value; }
            get { return mvarDaytuong; }
        }
        public Double CaotuongH
        {
            set { mvarCaotuongH = value; }
            get { return mvarCaotuongH; }
        }
        public Double SauckH4
        {
            set { mvarSauckH4 = value; }
            get { return mvarSauckH4; }
        }
        public Double SaubeH3
        {
            set { mvarSaubeH3 = value; }
            get { return mvarSaubeH3; }
        }
        public Double SaubeH2
        {
            set { mvarSaubeH2 = value; }
            get { return mvarSaubeH2; }
        }
        public Double SauckH1
        {
            set { mvarSauckH1 = value; }
            get { return mvarSauckH1; }
        }
        public long Sophandoan
        {
            set { mvarSophandoan = value; }
            get { return mvarSophandoan; }
        }
        public Object DocPd
        {
            set { mvarDocPd = value; }
            get { return mvarDocPd; }
        }
        public Double TlB
        {
            set { mvarTlB = value; }
            get { return mvarTlB; }
        }
        public Double Traiphai
        {
            set { mvarTraiphai = value; }
            get { return mvarTraiphai; }
        }
        public Boolean KTVuongGoc
        {
            set { mvarKtVuongGoc = value; }
            get { return mvarKtVuongGoc; }
        }
        public int Tl
        {
            set { mvarTl = value; }
            get { return mvarTl; }
        }
        public int TlT
        {
            set { mvarTlT = value; }
            get { return mvarTlT; }
        }
        public Double RongT
        {
            set { mvarRongT = value; }
            get { return mvarRongT; }
        }
        public Double RongD
        {
            set { mvarRongD = value; }
            get { return mvarRongD; }
        }
        Double Tinhcu(Double a)
        {
            return a * 10 / Com.HsTl(Tl, 1 - TlT);
        }
        Double TlDim
        {
            get { return Com.HsTl((Tl), TlT); }
        }
        public double n1d
        {
            get { return Math.Round((RongD - Daytuong - 0.5 * Ronggod) / (Ronggod + Ckgod1) - 0.5, 0); }
        }
        public double n1t
        {
            get { return Math.Round((RongT - Daytuong - 0.5 * Ronggod) / (Ronggod + Ckgod1) - 0.5, 0); }
        }
        public double numberRow1
        {
            get { return 2 * Math.Round(((RongT + RongD) / 2 - Daytuong - 0.5 * Ronggod) / (Ronggod + Ckgod1) - 0.5, 0) + 1; }
        }
        public double n2d
        {
            get { return Math.Round((RongD - Daytuong + 0.5 * Ckgod1) / (Ronggod + Ckgod1) - 0.5, 0); }
        }
        public double n2t
        {
            get { return Math.Round((RongT - Daytuong + 0.5 * Ckgod1) / (Ronggod + Ckgod1) - 0.5, 0); }
        }
        public double numberRow2
        {
            get { return 2 * Math.Round(((RongT + RongD) / 2 - Daytuong + 0.5 * Ckgod1) / (Ronggod + Ckgod1) - 0.5, 0); }
        }
        public double numberCol1
        {
            get { return Math.Round(Sophandoan / 2 + 0.1, 0); }
        }
        public double numberCol2
        {
            get { return Sophandoan - numberCol1; }
        }
        public String HatchName()
        {
            switch (VlTn.Substring(0, 3))
            {
                case "BTM": return "ansi31";
                case "DHX": return "Honey";
                default: return "Gravel";
            }
        }
        String MaterialName()
        {
            switch (VlTn)
            {
                case "BTM100":
                    return "Bê tông M100";

                case "BTM150":
                    return "Bê tông M150";

                case "BTM200":
                    return "Bê tông M200";

                case "BTM250":
                    return "Bê tông M250";

                case "BTM300":
                    return "Bê tông M300";

                case "DHMM75":
                    return "Đá hộc miết mạch M75";

                default:
                    return "Đá hộc xây vữa M100";
            }
        }
        //'************THKL************
        Double HsKichthuoc()
        {
            return 0.001 * Com.HsTl((Tl), 1 - TlT);
        }
        Double Diengiai(Double giatri, int phanthapphan=2)
        {
            return Math.Round(giatri * 0.001 * Com.HsTl((Tl), 1 - TlT), phanthapphan);
        }
        //'San
        Double VSan()
        {
            Double mVSan = new double();
            if (Sophandoan > 0 )
            {
                mVSan = (Sophandoan * Diengiai(DaisanL) * Diengiai(Daysanh1) + Diengiai(DaibeL1) * Diengiai(Daybeh2) + Diengiai(SaubeH3) * Diengiai(Daythanhbeb2)) * Diengiai(RongT + RongD) + Diengiai(DaisanL2 - Dayckb1) * Diengiai(DaysanH3) * Diengiai(RongT + RongD);

            }
            if (Sophandoan == 0)
            {
                mVSan = (Diengiai(DaibeL1) * Diengiai(Daybeh2) + Diengiai(SaubeH3) * Diengiai(Daythanhbeb2)) * Diengiai(RongT + RongD) + Diengiai(DaisanL2 - Dayckb1) * Diengiai(DaysanH3) * Diengiai(RongT + RongD);

            }
            return Math.Round(mVSan, 2);
        }
        String VSanDd()
        {
            string mVSanDd = "";
            if (Sophandoan > 0)
            {
                mVSanDd = "(" + Sophandoan + "*" + Diengiai(DaisanL) + "*" + Diengiai(Daysanh1) + "+" + Diengiai(DaibeL1) + "*" + Diengiai(Daybeh2) + "+" + Diengiai(SaubeH3) + "*" + Diengiai(Daythanhbeb2) + ")*" + Diengiai(RongT + RongD) + "+" + Diengiai(DaisanL2 - Dayckb1) + "*" + Diengiai(DaysanH3) + "*" + Diengiai(RongT + RongD);

            }
            if (Sophandoan == 0)
            {
                mVSanDd = "(" + Diengiai(DaibeL1) + "*" + Diengiai(Daybeh2) + "+" + Diengiai(SaubeH3) + "*" + Diengiai(Daythanhbeb2) + ")*" + Diengiai(RongT + RongD) + "+" + Diengiai(DaisanL2 - Dayckb1) + "*" + Diengiai(DaysanH3) + "*" + Diengiai(RongT + RongD);

            }
            return mVSanDd;
        }
        Double VkSan()
        {
            double mVkSan = new double();
            if (Sophandoan > 0)
            {
                mVkSan = 2 * Sophandoan * Diengiai(DaisanL) * Diengiai(Daysanh1) + 2 * Diengiai(DaibeL1) * Diengiai(Daybeh2) + 2 * Diengiai(SaubeH3) * Diengiai(Daythanhbeb2) + 2 * Diengiai(SaubeH3) * Diengiai(RongT + RongD);

            }
            if (Sophandoan == 0)
            {
                mVkSan = 2 * Diengiai(DaibeL1) * Diengiai(Daybeh2) + 2 * Diengiai(SaubeH3) * Diengiai(Daythanhbeb2) + 2 * Diengiai(SaubeH3) * Diengiai(RongT + RongD);

            }
            if (VlTn.Substring(0, 2) == "BT" )
            {
                return Math.Round(mVkSan, 2);
            }
            return 0;
        }
        String VkSanDd()
        {
            string mVkSanDd = "";
            if (Sophandoan > 0)
            {
                mVkSanDd = "2*" + Sophandoan + "*" + Diengiai(DaisanL) + "*" + Diengiai(Daysanh1) + "+2*" + Diengiai(DaibeL1) + "*" + Diengiai(Daybeh2) + "+2*" + Diengiai(SaubeH3) + "*" + Diengiai(Daythanhbeb2) + "+2*" + Diengiai(SaubeH3) + "*" + Diengiai(RongT + RongD);

            }
            if (Sophandoan == 0)
            {
                mVkSanDd = "2*" + Diengiai(DaibeL1) + "*" + Diengiai(Daybeh2) + "+2*" + Diengiai(SaubeH3) + "*" + Diengiai(Daythanhbeb2) + "+2*" + Diengiai(SaubeH3) + "*" + Diengiai(RongT + RongD);

            }
            return mVkSanDd;
        }
        //'Thanh san tieu nang
        Double VThanh()
        {
            Double mVThanh = new double();
            if (Sophandoan > 0)
            {
                mVThanh = 2 * Diengiai(Sophandoan * (DaisanL + Dayckb)) * Diengiai(CaotuongH) * Diengiai(Daytuong) + 2 * (Diengiai(SaubeH2 + CaotuongH) + Diengiai(SaubeH3)) / 2 * Diengiai(DaibeL1 - Daythanhbeb2) * Diengiai(Daytuong);

            }
            if (Sophandoan == 0)
            {
                mVThanh = 2 * (Diengiai(CaoH2 + SauCk - Daybeh2) + Diengiai(SaubeH3)) / 2 * Diengiai(DaibeL1 - Daythanhbeb2) * Diengiai(Daytuong);

            }
            return Math.Round(mVThanh, 2);
        }
        String VThanhDd()
        {
            String mVThanhDd = "";
            if (Sophandoan > 0)
            {
                mVThanhDd = "2*" + Diengiai(Sophandoan * (DaisanL + Dayckb)) + "*" + Diengiai(CaotuongH) + "*" + Diengiai(Daytuong) + "+2*(" + Diengiai(SaubeH2 + CaotuongH) + "+" + Diengiai(SaubeH3) + ")/2*" + Diengiai(DaibeL1 - Daythanhbeb2) + "*" + Diengiai(Daytuong);

            }
            if (Sophandoan == 0)
            {
                mVThanhDd = "2*(" + Diengiai(CaoH2 + SauCk - Daybeh2) + "+" + Diengiai(SaubeH3) + ")/2*" + Diengiai(DaibeL1 - Daythanhbeb2) + "*" + Diengiai(Daytuong);

            }
            return mVThanhDd;
        }
        Double VkThanh()
        {
            Double mVkThanh = new double();
            if (Sophandoan > 0)
            {
                mVkThanh = 4 * Diengiai(Sophandoan * (DaisanL + Dayckb)) * Diengiai(CaotuongH) + 4 * (Diengiai(SaubeH2 + CaotuongH) + Diengiai(SaubeH3)) / 2 * Diengiai(DaibeL1 - Daythanhbeb2);

            }
            if (Sophandoan == 0)
            {
                mVkThanh = 4 * (Diengiai(SaubeH2 + CaotuongH) + Diengiai(SaubeH3)) / 2 * Diengiai(DaibeL1 - Daythanhbeb2);
            }
            if (VlTn.Substring(0, 2) == "BT")
            {
                return Math.Round(mVkThanh, 2);
            }
            return 0;
        }
        String VkThanhDd()
        {
            String mVkThanhDd = "";
            if (Sophandoan > 0)
            {
                mVkThanhDd = "4*" + Diengiai(Sophandoan * (DaisanL + Dayckb)) + "*" + Diengiai(CaotuongH) + "+4*(" + Diengiai(SaubeH2 + CaotuongH) + "+" + Diengiai(SaubeH3) + ")/2*" + Diengiai(DaibeL1 - Daythanhbeb2);

            }
            if (Sophandoan == 0)
            {
                mVkThanhDd = "4*(" + Diengiai(CaoH2 + SauCk - Daybeh2) + "+" + Diengiai(SaubeH3) + ")/2*" + Diengiai(DaibeL1 - Daythanhbeb2);

            }
            return mVkThanhDd;
        }
        //'Chan khay
        Double VCk()
        {
            Double mVCk = new double();
            if (Sophandoan > 0)
            {
                mVCk = (Sophandoan - 1) * Diengiai(SauckH1) * Diengiai(Dayckb) * Diengiai(RongT + RongD) + Diengiai(SaubeH2 + Daybeh2) * Diengiai(Dayckb) * Diengiai(RongT + RongD) + Diengiai(SauckH4) * Diengiai(Dayckb1) * Diengiai(RongT + RongD);
                
            }
            return Math.Round(mVCk, 2);
            
        }
        String VCkDd()
        {
            String mVCkDd = "";
            if (Sophandoan > 0)
            {
                mVCkDd = (Sophandoan - 1) + "*" + Diengiai(SauckH1) + "*" + Diengiai(Dayckb) + "*" + Diengiai(RongT + RongD) + "+" + Diengiai(SaubeH2 + Daybeh2) + "*" + Diengiai(Dayckb) + "*" + Diengiai(RongT + RongD) + "+" + Diengiai(SauckH4) + "*" + Diengiai(Dayckb1) + "*" + Diengiai(RongT + RongD);

            }
            return mVCkDd;
        }
        Double VkCk()
        {
            Double mVkCk = new double();
            if (Sophandoan > 0)
            {
                mVkCk = 2 * (Sophandoan - 1) * Diengiai(SauckH1 - Daysanh1) * Diengiai(RongT + RongD) + 2 * Diengiai(SaubeH2) * Diengiai(RongT + RongD) + 2 * Diengiai(SauckH4) * Diengiai(RongT + RongD);

            }
          
            if (VlTn.Substring(0, 2) == "BT")
            {
                return Math.Round(mVkCk, 2);
            }
            return 0;
        }
        String VkCkDd()
        {
            String mVkCkDd = "";
            if (Sophandoan > 0)
            {
                mVkCkDd = 2 * (Sophandoan - 1) + "*" + Diengiai(SauckH1 - Daysanh1) + "*" + Diengiai(RongT + RongD) + "+2*" + Diengiai(SaubeH2) + "*" + Diengiai(RongT + RongD) + "+2*" + Diengiai(SauckH4) + "*" + Diengiai(RongT + RongD);

            }
            return mVkCkDd;
        }
        //'Go tieu nang
        Double Vgo()
        {
            Double mVgo = new double();
            if (Sophandoan > 0)
            {
                mVgo = (numberRow1 * numberCol1 + numberRow2 * numberCol2) * Diengiai(CaotuongH) * Diengiai(Dayckb) * Diengiai(Ronggod);

            }
            return Math.Round(mVgo, 2);
        }
        String VgoDd()
        {
            String mVgoDd = "";
            if (Sophandoan > 0)
            {
                mVgoDd = (numberRow1 * numberCol1 + numberRow2 * numberCol2) + "*" + Diengiai(CaotuongH) + "*" + Diengiai(Dayckb) + "*" + Diengiai(Ronggod);

            }
            return mVgoDd;
        }
        Double Vkgo() 
        {
            Double mVkgo = new double();
            if (Sophandoan > 0)
            {
                mVkgo = (numberRow1 * numberCol1 + numberRow2 * numberCol2) * 2 * (Diengiai(Dayckb) + Diengiai(Ronggod)) * Diengiai(CaotuongH);

            }
            if (VlTn.Substring(0, 2) == "BT")
            {
                return Math.Round(mVkgo, 2);
            }
            return 0;
        }
        String VkgoDd() 
        {
            String mVkgoDd = "";
            if (Sophandoan > 0)
            {
                mVkgoDd = (numberRow1 * numberCol1 + numberRow2 * numberCol2) + "*2*(" + Diengiai(Dayckb) + "+" + Diengiai(Ronggod) + ")*" + Diengiai(CaotuongH);

            }
            return mVkgoDd;

        }
        //'Lop dem mong
        Double VLopdem() 
        {
            double mVLopdem = new double();
            if (Sophandoan > 0)
            {
                mVLopdem = Diengiai(Sophandoan * (DaisanL + Dayckb) + DaibeL1 + DaisanL2) * Diengiai(RongT + RongD) * Diengiai(Lopdem);

            }
            if (Sophandoan == 0)
            {
                mVLopdem = Diengiai(DaibeL1 + DaisanL2) * Diengiai(RongT + RongD) * Diengiai(Lopdem);

            }
            return Math.Round(mVLopdem, 2);
        }
        String VLopdemDd()
        {
            String mVLopdemDd = "";
            if (Sophandoan > 0)
            {
                mVLopdemDd = Diengiai(Sophandoan * (DaisanL + Dayckb) + DaibeL1 + DaisanL2) + "*" + Diengiai(RongT + RongD) + "*" + Diengiai(Lopdem);

            }
            if (Sophandoan == 0)
            {
                mVLopdemDd = Diengiai(DaibeL1 + DaisanL2) + "*" + Diengiai(RongT + RongD) + "*" + Diengiai(Lopdem);
            }
            return mVLopdemDd;
        }
    }
}
